<template>
  <div class="clubsListBox">
    <div>
      <el-form :model="queryData" ref="queryForm" size="small" :inline="true">
        <el-form-item label="活动地址">
          <el-input
            v-model="queryData.address"
            placeholder="请输入活动地址"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="社团">
          <el-select
            v-model="queryData.clubId"
            clearable
            filterable
            placeholder="请选择社团"
          >
            <el-option
              v-for="item in club"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div v-if="formData.length">
      <div
        v-for="(e, i) in formData"
        :key="i"
        class="activite-box"
        :class="{ 'last-activite-box': i === formData.length - 1 }"
      >
        <div class="activite-subject">
          <div style="display: flex">
            <div style="position: relative; display: inline-block">
              {{ e.subject }}
              <div class="activite-tip">
                <p v-show="e.club" class="activite-club">{{ e.club }}</p>
                <p class="activite-type">{{ e.activityType }}</p>
              </div>
            </div>
            <div style="margin-left: 20px;">
              <el-tag type="info" v-if="e.status === 0">未报名</el-tag>
              <el-tag type="success" v-else-if="e.status === 1">报名中</el-tag>
              <el-tag v-else-if="e.status === 2">进行中</el-tag>
              <el-tag type="danger" v-else-if="e.status === 3">已结束</el-tag>
            </div>
          </div>
          <el-button
            type="primary"
            round
            class="activite-button"
            @click="goActivitieDetails(e)"
            >查看详情</el-button
          >
        </div>
        <div class="flex fsz26">
          <p>
            报名时间：{{ formattedDate(e.joinStart) }} -
            {{ formattedDate(e.joinEnd) }}
          </p>
          <p style="margin-left: 2vw">
            活动时间：{{ formattedDate(e.activityStart) }} -
            {{ formattedDate(e.activityEnd) }}
          </p>
        </div>
        <!-- <p class="fsz26">活动地址：{{ e.address }}</p> -->
        <!-- <p class="fsz26">联系方式：{{ e.contactInfo }}</p> -->
        <!-- <div class="flex fsz26">
          <p>活动规则：</p>
          <p class="text2">{{ e.rules }}</p>
        </div>
        <div class="flex fsz26">
          <p>奖项设置：</p>
          <p class="text2">{{ e.awardSettings }}</p>
        </div> -->
      </div>
      <!-- 分页  -->
      <pagination
        class="pagination"
        v-show="total > 0"
        :total="total"
        :page.sync="queryData.pageNum"
        :limit.sync="queryData.pageSize"
        @pagination="getList"
      />
    </div>
    <div
      style="font-size: 2.395vw; text-align: center; margin: 2.083vw 0"
      v-else
    >
      暂无活动
    </div>
  </div>
</template>

<script>
import { select } from "@/api/organizations/index.js";
import { getActivityLists } from "@/api/cms/cms.js";
import Pagination from "@/components/Pagination/index.vue";

export default {
  components: {
    Pagination,
  },
  data() {
    return {
      club: [],
      queryData: {
        address: "",
        clubId: "",
        pageNum: 1,
        pageSize: 10,
      },

      formData: [],
      total: 0,
    };
  },
  async created() {
    await this.getClubsByPage();
    this.getActivityList();
  },
  methods: {
    getClubsByPage(data) {
      return new Promise((resolve) => {
        select({
          pageNum: 1,
          pageSize: 99999999,
          data,
        }).then((res) => {
          const { JoinClubsByPage } = res.data;
          this.club = JoinClubsByPage.records;
          resolve();
        });
      });
    },
    formattedDate(time) {
      const date = new Date(time);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, "0");
      const day = date.getDate().toString().padStart(2, "0");
      const hours = date.getHours().toString().padStart(2, "0");
      const minutes = date.getMinutes().toString().padStart(2, "0");
      return `${year}-${month}-${day} ${hours}:${minutes}`;
    },
    handleQuery() {
      this.queryData.pageNum = 1;
      this.getActivityList();
    },
    getActivityList() {
      getActivityLists(
        this.queryData.pageNum,
        this.queryData.pageSize,
        this.queryData
      ).then((res) => {
        if (res.code == 20000) {
          this.formData = res.data.list.records;
          this.total = res.data.list.total;
          // this.activityData = res.data.list
          this.formData.forEach((e) => {
            const club = this.club.filter((es) => es.id == e.clubId);
            e.club = club.length ? club[0].name : "";
          });
          console.log(this.formData);
        }
      });
    },
    getList(e) {
      this.queryData.pageNum = e.page;
      this.queryData.pageSize = e.limit;
      this.getActivityList();
    },
    goActivitieDetails(e) {
      this.$router.push(`/activitieDetails?id=${e.id}`);
    },
  },
};
</script>

<style scoped>
p {
  margin: 0;
  padding: 0;
}
.clubsListBox {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

/* 表单样式 */
::v-deep .el-form {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 30px;
}

::v-deep .el-form-item {
  margin-bottom: 18px;
  margin-right: 30px;
}

::v-deep .el-form-item__label {
  font-weight: 500;
  color: #606266;
}

::v-deep .el-input__inner {
  border-radius: 20px;
  transition: all 0.3s;
}

::v-deep .el-button--primary {
  background: linear-gradient(135deg, #409eff, #3375b9);
  border: none;
  border-radius: 20px;
  padding: 9px 20px;
  transition: all 0.3s;
}

/* 活动卡片 */
.activite-box {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;
  border: 1px solid #ebeef5;
}

.activite-box:hover {
  transform: translateY(-3px);
}

.activite-subject {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  font-size: 1.2rem;
  font-weight: 600;
  color: #303133;
}

.activite-tip {
  display: flex;
  gap: 10px;
  margin-left: 15px;
  margin-top: 10px;
}

.activite-club,
.activite-type {
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 15px;
  font-weight: 500;
}

.activite-club {
  background: #67c23a;
  color: #fff;
}

.activite-type {
  background: #409eff;
  color: #fff;
}

/* 信息内容样式 */
.fsz26 {
  font-size: 0.95rem;
  color: #606266;
  line-height: 1.6;
  margin: 8px 0;
}

.fsz26 p:first-child {
  color: #909399;
  min-width: 80px;
  font-weight: 500;
}

.flex {
  display: flex;
  align-items: baseline;
  margin: 12px 0;
  gap: 0px;
  flex-direction: column;
}

/* 查看详情按钮 */
.activite-button {
  background: linear-gradient(135deg, #409eff, #3375b9);
  border: none;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(64, 158, 255, 0.3);
}

.activite-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
}

/* 分页样式 */
.pagination {
  margin-top: 30px;
  text-align: center;
}

/* 无数据提示 */
.clubsListBox > div:empty::before {
  content: "暂无活动";
  display: block;
  text-align: center;
  color: #909399;
  padding: 40px;
  font-size: 1.1rem;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .clubsListBox {
    padding: 10px;
  }

  .activite-subject {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .flex {
    flex-direction: column;
    gap: 0px;
  }

  .text2 {
    text-indent: 2em;
  }
}
</style>